package com.bdqn.ch05jsp.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpSession;

@Controller
public class LoginController {

    Logger logger = LoggerFactory.getLogger(HelloController.class);

    @RequestMapping("/login")   //@PathVariable  //@RequestParam
    public String login(@RequestParam(value = "uname") String unameaa,
                        @RequestParam(value = "upwd") String upwdaa, HttpSession session) {
        logger.warn("uname:" + unameaa);
        logger.warn("upwd:" + upwdaa);
        if (unameaa.equals("admin") && upwdaa.equals("123")) {
            session.setAttribute("sessionuser",unameaa);
            return "main";
        } else {
            return "redirect:/login.jsp";
        }
    }
}
